package com.health.fragment.focusgroup;

import android.annotation.SuppressLint;
import android.graphics.Color;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;

import com.health.R;
import com.health.adapter.CheckBoxAdapter;
import com.health.adapter.RadioButtonAdapter;
import com.health.db.FDbManager;
import com.health.fragment.NovaFragment;
import com.health.tablebean.BD_DD_INFO;
import com.health.tablebean.BD_ORGANIZE_EMPLOYEE;
import com.health.tablebean.CD_TUBERCULOSIS_BASEINFO;
import com.health.tools.GlobalConts;
import com.health.view.spinner.NiceSpinner;
import com.health.viewscontrols.NovaApplication;
import com.health.viewscontrols.PersonalFileActivity.onFragmentSave;
import com.health.viewscontrols.focusgroup.FJHActivity;
import com.health.widget.EditTextWithDate;
import com.health.widget.MyGridView;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * 重点人群-- 肺结核---基本信息
 */
public class FJH_BaseFragment extends NovaFragment implements onFragmentSave {
    private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    Unbinder unbinder;
    private FDbManager fdbmanger;
    /**
     * 姓名
     */
    @BindView(R.id.tv_name)
    TextView tvName;
    /**
     * 随访时间
     */
    @BindView(R.id.ed_date)
    EditTextWithDate edDate;
    /**
     * 随访方式
     */
    @BindView(R.id.gd_sf)
    MyGridView gdSf;
    /**
     * 症状及体征
     */
    @BindView(R.id.gd_zz)
    MyGridView gdZz;
    /**
     * 化疗方案
     */
    @BindView(R.id.et_hlfa)
    EditText etHlfa;
    /**
     * 用法
     */
    @BindView(R.id.gd_yf)
    MyGridView gdYf;
    /**
     * 药品剂型
     */
    @BindView(R.id.gd_ypjx)
    MyGridView gdYpjx;
    /**
     * 督导人员
     */
    @BindView(R.id.gd_ddry)
    MyGridView gdDdry;
    /**
     * 单独的居室
     */
    @BindView(R.id.gd_ddjs)
    MyGridView gdDdjs;
    /**
     * 通风情况
     */
    @BindView(R.id.gd_tfqk)
    MyGridView gdTfqk;
    /**
     * 吸烟（日吸烟量）
     */
    @BindView(R.id.et_rxy)
    EditText etRxy;
    /**
     * 吸烟（目标吸烟量）
     */
    @BindView(R.id.et_mbxy)
    EditText etMbxy;
    /**
     * 饮酒（日饮酒）
     */
    @BindView(R.id.et_ryj)
    EditText etRyj;
    /**
     * 饮酒（目标饮酒）
     */
    @BindView(R.id.et_mbyj)
    EditText etMbyj;
    /**
     * 地点
     */
    @BindView(R.id.et_dd)
    EditText etDd;
    /**
     * 时间
     */
    @BindView(R.id.ed_date_qy)
    EditTextWithDate edDateQy;
    /**
     * 服药记录卡的填写
     */
    @BindView(R.id.gd_jlktx)
    MyGridView gdJlktx;
    /**
     * 服药方法及药品存放
     */
    @BindView(R.id.gd_ffjypcf)
    MyGridView gdFfjypcf;
    /**
     * 肺结核治疗过程
     */
    @BindView(R.id.gd_zlgc)
    MyGridView gdZlgc;
    /**
     * 不规律服药危害
     */
    @BindView(R.id.gd_bglfywh)
    MyGridView gdBglfywh;
    /**
     * 服药后不良反应及处理
     */
    @BindView(R.id.gd_blfycl)
    MyGridView gdBlfycl;
    /**
     * 治疗期间复诊查痰
     */
    @BindView(R.id.gd_fzct)
    MyGridView gdFzct;
    /**
     * 外出期间如何坚持服药
     */
    @BindView(R.id.gd_rhjcfy)
    MyGridView gdRhjcfy;
    /**
     * 生活习惯及注意事项
     */
    @BindView(R.id.gd_zysx)
    MyGridView gdZysx;
    /**
     * 密切接触者检查
     */
    @BindView(R.id.gd_mqjczjc)
    MyGridView gdMqjczjc;


    /**
     * 患者类型
     */
    @BindView(R.id.gd_hzlx)
    MyGridView gdHzlx;
    /**
     * 痰菌情况
     */
    @BindView(R.id.gd_tjqk)
    MyGridView gdTjqk;
    /**
     * 耐药情况
     */
    @BindView(R.id.gd_nyqk)
    MyGridView gdNyqk;
    /**
     * 下次随访时间
     */
    @BindView(R.id.ed_xcsfsj)
    EditTextWithDate edXcsfsj;
    /**
     * 评估医生签名
     */
    @BindView(R.id.ns_pjys)
    NiceSpinner nsPjys;
    /**
     * 随访方式
     */
    private RadioButtonAdapter adapterSf;
    /**
     * 患者类型
     */
    private RadioButtonAdapter adapterHzlx;
    /**
     * 痰菌情况
     */
    private RadioButtonAdapter adapterTjqk;
    /**
     * 耐药情况
     */
    private RadioButtonAdapter adapterNyqk;
    /**
     * 症状及体征
     */
    private CheckBoxAdapter adapterZzjtz;
    /**
     * 用法
     */
    private RadioButtonAdapter adapterYf;
    /**
     * 药品剂型
     */
    private CheckBoxAdapter adapterYpjx;
    /**
     * 督导人员
     */
    private RadioButtonAdapter adapterDdry;
    /**
     * 单独居室
     */
    private RadioButtonAdapter adapterDdjs;
    /**
     * 通风情况
     */
    private RadioButtonAdapter adapterTfqk;
    /**
     * 健康教育及培训
     */
    private RadioButtonAdapter adapterJkjy;
    /**
     * 健康教育及培训1
     */
    private RadioButtonAdapter adapterJkjy1;
    /**
     * 健康教育及培训2
     */
    private RadioButtonAdapter adapterJkjy2;
    /**
     * 健康教育及培训3
     */
    private RadioButtonAdapter adapterJkjy3;
    /**
     * 健康教育及培训4
     */
    private RadioButtonAdapter adapterJkjy4;
    /**
     * 健康教育及培训5
     */
    private RadioButtonAdapter adapterJkjy5;
    /**
     * 健康教育及培训6
     */
    private RadioButtonAdapter adapterJkjy6;
    /**
     * 健康教育及培训7
     */
    private RadioButtonAdapter adapterJkjy7;
    /**
     * 健康教育及培训8
     */
    private RadioButtonAdapter adapterJkjy8;

    private CD_TUBERCULOSIS_BASEINFO cdTuberculosisBaseinfo;
    /**
     * 保存标识 -1:未创建档案、1：保存成功
     */
    private int fromFollowup = -1;

    @SuppressLint("InflateParams")
    @Override
    public View findViews(LayoutInflater inflater) {
        fdbmanger = NovaApplication.fdbmanger;
        return inflater.inflate(R.layout.fjh_base, null);
    }


    @Override
    public void setupView(View view) {
        unbinder = ButterKnife.bind(this, view);
        edDate.setBefore(true);
        edXcsfsj.setAfter(true,0);
        GlobalConts.restrictionLength(etRxy, etMbxy, etRyj, etMbyj);
    }

    @Override
    public void addListener() {
    }

    @Override
    public void setData() {
        GlobalConts.doctorList(nsPjys);
        tvName.setText("姓名："+ NovaApplication.getUserInfo().getCUSTOMERNAME());
        bindDdata("随访方式", "PARENTID='DM04-15'");
        bindDdata("患者类型", "PARENTID='DM102-01'");
        bindDdata("痰菌情况", "PARENTID='DM102-02'");
        bindDdata("耐药情况", "PARENTID='DM102-03'");
        bindDdata("症状及体征", "PARENTID='DM102-04'");
        bindDdata("用法", "PARENTID='DM102-05'");
        bindDdata("药品剂型", "PARENTID='DM102-06'");
        bindDdata("督导人员", "PARENTID='DM102-07'");
        bindDdata("单独居室", "PARENTID='DM01-102'");
        bindDdata("通风情况", "PARENTID='DM01-69'");
        bindDdata("健康教育及培训", "PARENTID='DM102-08'");
        getSaveArchivesInfo();
    }

    /**
     * 绑定数据值
     *
     * @author 王婷婷
     * @date 2015年12月17日 上午10:30:30
     */
    private void bindDdata(String flag, String strWhere) {
        List<BD_DD_INFO> listZZs = fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class, strWhere);
        if ("随访方式".equals(flag)) {
            int size = listZZs.size();
            List<BD_DD_INFO> list = new ArrayList<>();
            if (size > 0) {
                for (BD_DD_INFO info : listZZs) {
                    String id = info.getID();
                    if (!"DM04-04_3".equals(id)) {
                        list.add(info);
                    }
                }
            }
            adapterSf = new RadioButtonAdapter(list, getActivity());
            gdSf.setAdapter(adapterSf);
        } else if ("患者类型".equals(flag)) {
            adapterHzlx = new RadioButtonAdapter(listZZs, getActivity());
            gdHzlx.setAdapter(adapterHzlx);
        } else if ("痰菌情况".equals(flag)) {
            adapterTjqk = new RadioButtonAdapter(listZZs, getActivity());
            gdTjqk.setAdapter(adapterTjqk);
        } else if ("耐药情况".equals(flag)) {
            adapterNyqk = new RadioButtonAdapter(listZZs, getActivity());
            gdNyqk.setAdapter(adapterNyqk);
        } else if ("症状及体征".equals(flag)) {
            adapterZzjtz = new CheckBoxAdapter(getActivity(), listZZs);
            gdZz.setAdapter(adapterZzjtz);
        } else if ("用法".equals(flag)) {
            adapterYf = new RadioButtonAdapter(listZZs, getActivity());
            gdYf.setAdapter(adapterYf);
        } else if ("药品剂型".equals(flag)) {
            adapterYpjx = new CheckBoxAdapter(getActivity(), listZZs);
            gdYpjx.setAdapter(adapterYpjx);
        } else if ("督导人员".equals(flag)) {
            adapterDdry = new RadioButtonAdapter(listZZs, getActivity());
            adapterDdry.setOtherTextVisible(false);
            gdDdry.setAdapter(adapterDdry);
        } else if ("单独居室".equals(flag)) {
            adapterDdjs = new RadioButtonAdapter(listZZs, getActivity());
            gdDdjs.setAdapter(adapterDdjs);
        } else if ("通风情况".equals(flag)) {
            int size = listZZs.size();
            List<BD_DD_INFO> list = new ArrayList<>();
            if (size > 0) {
                for (BD_DD_INFO info : listZZs) {
                    String id = info.getID();
                    if ("DM01-69_1".equals(id) || "DM01-69_2".equals(id) || "DM01-69_3".equals(id)) {
                        list.add(info);
                    }
                }
            }
            adapterTfqk = new RadioButtonAdapter(list, getActivity());
            gdTfqk.setAdapter(adapterTfqk);
        } else if ("健康教育及培训".equals(flag)) {
            adapterJkjy = new RadioButtonAdapter(listZZs, getActivity());
            adapterJkjy1 = new RadioButtonAdapter(listZZs, getActivity());
            adapterJkjy2 = new RadioButtonAdapter(listZZs, getActivity());
            adapterJkjy3 = new RadioButtonAdapter(listZZs, getActivity());
            adapterJkjy4 = new RadioButtonAdapter(listZZs, getActivity());
            adapterJkjy5 = new RadioButtonAdapter(listZZs, getActivity());
            adapterJkjy6 = new RadioButtonAdapter(listZZs, getActivity());
            adapterJkjy7 = new RadioButtonAdapter(listZZs, getActivity());
            adapterJkjy8 = new RadioButtonAdapter(listZZs, getActivity());
            gdJlktx.setAdapter(adapterJkjy);
            gdFfjypcf.setAdapter(adapterJkjy1);
            gdZlgc.setAdapter(adapterJkjy2);
            gdBglfywh.setAdapter(adapterJkjy3);
            gdBlfycl.setAdapter(adapterJkjy4);
            gdFzct.setAdapter(adapterJkjy5);
            gdRhjcfy.setAdapter(adapterJkjy6);
            gdZysx.setAdapter(adapterJkjy7);
            gdMqjczjc.setAdapter(adapterJkjy8);
        }
    }

    @Override
    public void save() {
        if (TextUtils.isEmpty(edDate.getText().toString())) {
            edDate.setBackgroundColor(Color.YELLOW);
            ((FJHActivity) getActivity()).showTextDialog("请选择随访时间");
            return;
        } else {
            edDate.setBackgroundColor(Color.WHITE);
        }
        if (TextUtils.isEmpty(edXcsfsj.getText().toString())) {
            edXcsfsj.setBackgroundColor(Color.YELLOW);
            ((FJHActivity) getActivity()).showTextDialog("请选择下次随访时间");
            return;
        } else {
            edXcsfsj.setBackgroundColor(Color.WHITE);
        }
        if (TextUtils.isEmpty(NovaApplication.getDoctorList().get(nsPjys.getSelectedIndex()).getUSER_ID())) {
            edXcsfsj.setBackgroundColor(Color.YELLOW);
            ((FJHActivity) getActivity()).showTextDialog("请选择评估医生");
            return;
        } else {
            edXcsfsj.setBackgroundColor(Color.WHITE);
        }
        cdTuberculosisBaseinfo = new CD_TUBERCULOSIS_BASEINFO();
        cdTuberculosisBaseinfo.setIS_UPDATE("Y");
        saveBaseInfo();
        saveMedication();
        saveSupervisorSelection();
        saveLifestyleEvaluation();
        savejkjyjpx();
        saveAndUpdatedArchivesInfo();
    }

    /**
     * 保存基本信息
     */
    private void saveBaseInfo() {
        cdTuberculosisBaseinfo.setCARDID(NovaApplication.getUserInfo().getIDCARD());
        try {
            cdTuberculosisBaseinfo.setHAPPENTIME(dateFormat.parse(edDate.getText().toString()));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        cdTuberculosisBaseinfo.setVISIT_WAY(adapterSf.getChecked());
        cdTuberculosisBaseinfo.setTUBER_TYPE(adapterHzlx.getChecked());
        cdTuberculosisBaseinfo.setTUBER_TJQK(adapterTjqk.getChecked());
        cdTuberculosisBaseinfo.setTUBER_NYQK(adapterNyqk.getChecked());
        cdTuberculosisBaseinfo.setTUBER_ZZTZ(getCheckedBD_DD_INFO(adapterZzjtz));
    }

    /**
     * 保存用药
     */
    private void saveMedication() {
        cdTuberculosisBaseinfo.setTUBER_HLFA(etHlfa.getText().toString());
        cdTuberculosisBaseinfo.setTUBER_YF(adapterYf.getChecked());
        cdTuberculosisBaseinfo.setTUBER_YPJX(adapterYpjx.getCheckedIdsStr());
    }

    /**
     * 保存督导人员选择、家庭居住环境评估
     */
    private void saveSupervisorSelection() {
        cdTuberculosisBaseinfo.setTUBER_DDRYXZ(adapterDdry.getChecked());
        cdTuberculosisBaseinfo.setTUBER_DDJS(adapterDdjs.getChecked());
        cdTuberculosisBaseinfo.setTUBER_TFQK(adapterTfqk.getChecked());
    }

    /**
     * 保存生活方式评估
     */
    private void saveLifestyleEvaluation() {
        cdTuberculosisBaseinfo.setSMOKE(etRxy.getText().toString());
        cdTuberculosisBaseinfo.setTARGET_SMOKE(etMbxy.getText().toString());
        cdTuberculosisBaseinfo.setDRINK(etRxy.getText().toString());
        cdTuberculosisBaseinfo.setTARGET_DRINK(etMbxy.getText().toString());
    }

    /**
     * 保存健康教育及培训
     */
    private void savejkjyjpx() {
        cdTuberculosisBaseinfo.setTUBER_QYDD(etDd.getText().toString());
        cdTuberculosisBaseinfo.setTUBER_QYSJ(edDateQy.getText().toString());
        cdTuberculosisBaseinfo.setTUBER_JLK(adapterJkjy.getChecked());
        cdTuberculosisBaseinfo.setTUBER_FYFF(adapterJkjy1.getChecked());
        cdTuberculosisBaseinfo.setTUBER_ZLLC(adapterJkjy2.getChecked());
        cdTuberculosisBaseinfo.setTUBER_WH(adapterJkjy3.getChecked());
        cdTuberculosisBaseinfo.setTUBER_BLFY(adapterJkjy4.getChecked());
        cdTuberculosisBaseinfo.setTUBER_FZCT(adapterJkjy5.getChecked());
        cdTuberculosisBaseinfo.setTUBER_RHFY(adapterJkjy6.getChecked());
        cdTuberculosisBaseinfo.setTUBER_SHXG(adapterJkjy7.getChecked());
        cdTuberculosisBaseinfo.setTUBER_JCZJC(adapterJkjy8.getChecked());
        cdTuberculosisBaseinfo.setNEXT_VISIT_DATE(edXcsfsj.getDate());
        cdTuberculosisBaseinfo.setTUBER_PGYSQM(NovaApplication.getDoctorList().get(nsPjys.getSelectedIndex()).getUSER_ID());
    }

    /**
     * 保存或更新基本档案信息
     */
    private void saveAndUpdatedArchivesInfo() {
        switch (fromFollowup) {
            case -1:
                cdTuberculosisBaseinfo.setCREATER(NovaApplication.getDoctorList().get(nsPjys.getSelectedIndex()).getUSER_ID());
                cdTuberculosisBaseinfo.setCREATEORG(NovaApplication.getDoctorList().get(nsPjys.getSelectedIndex()).getORGANCODE());
                cdTuberculosisBaseinfo.setCREATETIME(new Date());
                fdbmanger.save(cdTuberculosisBaseinfo);
                fromFollowup = 1;
                ((FJHActivity) getActivity()).showTextDialog("保存成功");
                break;
            case 1:
                cdTuberculosisBaseinfo.setMODIFIED(NovaApplication.getDoctorList().get(nsPjys.getSelectedIndex()).getUSER_ID());
                cdTuberculosisBaseinfo.setUPDATEORG(NovaApplication.getDoctorList().get(nsPjys.getSelectedIndex()).getORGANCODE());
                cdTuberculosisBaseinfo.setUPDATETIME(new Date());
                fdbmanger.updata(cdTuberculosisBaseinfo, "CARDID='" + NovaApplication.getUserInfo().getIDCARD() + "'");
                ((FJHActivity) getActivity()).showTextDialog("修改成功");
                break;
            default:
        }
    }

    /**
     * 获取保存的档案信息
     */
    private void getSaveArchivesInfo() {
        List<CD_TUBERCULOSIS_BASEINFO> allByWhere = fdbmanger.findAllByWhere(CD_TUBERCULOSIS_BASEINFO.class, "CARDID='" + NovaApplication.getUserInfo().getIDCARD() + "'");
        if (allByWhere.size() > 0) {
            fromFollowup = 1;
            setBaseInfo(allByWhere);
        } else {
            edDate.setDate(new Date());
            fromFollowup = -1;
        }
    }

    /**
     * 设置基本信息
     *
     * @param allByWhere 基本信息
     */
    private void setBaseInfo(List<CD_TUBERCULOSIS_BASEINFO> allByWhere) {
        setBaseInfo(allByWhere.get(0));
        getMedication(allByWhere.get(0));
        getSupervisorSelection(allByWhere.get(0));
        getLifestyleEvaluation(allByWhere.get(0));
        getjkjyjpx(allByWhere.get(0));
    }

    /**
     * 获取基本信息设置到组建上
     */
    private void setBaseInfo(CD_TUBERCULOSIS_BASEINFO cdTuberculosisBaseinfo) {
        edDate.setDate(cdTuberculosisBaseinfo.getHAPPENTIME());
        adapterSf.setChecked(cdTuberculosisBaseinfo.getVISIT_WAY());
        adapterHzlx.setChecked(cdTuberculosisBaseinfo.getTUBER_TYPE());
        adapterTjqk.setChecked(cdTuberculosisBaseinfo.getTUBER_TJQK());
        adapterNyqk.setChecked(cdTuberculosisBaseinfo.getTUBER_NYQK());
        adapterZzjtz.setCheckedCodeList(splitString(cdTuberculosisBaseinfo.getTUBER_ZZTZ()));
    }

    /**
     * 获取用药模块信息设置到组建上
     */
    private void getMedication(CD_TUBERCULOSIS_BASEINFO cdTuberculosisBaseinfo) {
        etHlfa.setText(cdTuberculosisBaseinfo.getTUBER_HLFA());
        adapterYf.setChecked(cdTuberculosisBaseinfo.getTUBER_YF());
        adapterYpjx.setCheckedCodeList(splitString(cdTuberculosisBaseinfo.getTUBER_YPJX()));
    }

    /**
     * 设置督导人员选择、家庭居住环境评估
     */
    private void getSupervisorSelection(CD_TUBERCULOSIS_BASEINFO cdTuberculosisBaseinfo) {
        adapterDdry.setChecked(cdTuberculosisBaseinfo.getTUBER_DDRYXZ());
        adapterDdjs.setChecked(cdTuberculosisBaseinfo.getTUBER_DDJS());
        adapterTfqk.setChecked(cdTuberculosisBaseinfo.getTUBER_TFQK());
    }

    /**
     * 设置生活方式评估
     */
    private void getLifestyleEvaluation(CD_TUBERCULOSIS_BASEINFO cdTuberculosisBaseinfo) {
        etRxy.setText(cdTuberculosisBaseinfo.getSMOKE());
        etMbxy.setText(cdTuberculosisBaseinfo.getTARGET_SMOKE());
        etRyj.setText(cdTuberculosisBaseinfo.getDRINK());
        etMbyj.setText(cdTuberculosisBaseinfo.getTARGET_DRINK());
    }

    /**
     * 设置健康教育及培训
     */
    private void getjkjyjpx(CD_TUBERCULOSIS_BASEINFO cdTuberculosisBaseinfo) {
        etDd.setText(cdTuberculosisBaseinfo.getTUBER_QYDD());
        edDateQy.setText(cdTuberculosisBaseinfo.getTUBER_QYSJ());
        adapterJkjy.setChecked(cdTuberculosisBaseinfo.getTUBER_JLK());
        adapterJkjy1.setChecked(cdTuberculosisBaseinfo.getTUBER_FYFF());
        adapterJkjy2.setChecked(cdTuberculosisBaseinfo.getTUBER_ZLLC());
        adapterJkjy3.setChecked(cdTuberculosisBaseinfo.getTUBER_WH());
        adapterJkjy4.setChecked(cdTuberculosisBaseinfo.getTUBER_BLFY());
        adapterJkjy5.setChecked(cdTuberculosisBaseinfo.getTUBER_FZCT());
        adapterJkjy6.setChecked(cdTuberculosisBaseinfo.getTUBER_RHFY());
        adapterJkjy7.setChecked(cdTuberculosisBaseinfo.getTUBER_SHXG());
        adapterJkjy8.setChecked(cdTuberculosisBaseinfo.getTUBER_JCZJC());
        edXcsfsj.setDate(cdTuberculosisBaseinfo.getNEXT_VISIT_DATE());
        List<BD_ORGANIZE_EMPLOYEE> doctorList = NovaApplication.getDoctorList();
        if (doctorList.size() > 0) {
            for (int i = 0; i < doctorList.size(); i++) {
                if (doctorList.get(i).getUSER_ID().equals(cdTuberculosisBaseinfo.getTUBER_PGYSQM())) {
                    nsPjys.setSelectedIndex(i);
                }
            }
        }
    }

    /**
     * 获取多选框的值
     *
     * @param mAdapter 适配器
     * @return 选择的值
     */
    private String getCheckedBD_DD_INFO(CheckBoxAdapter mAdapter) {
        if (null != mAdapter) {
            ArrayList<BD_DD_INFO> checkedBD_dd_info = mAdapter.getCheckedBD_DD_INFO();
            if (checkedBD_dd_info.size() > 0) {
                StringBuffer stringBuffer = new StringBuffer();
                for (BD_DD_INFO item : checkedBD_dd_info) {
                    stringBuffer.append(item.getID());
                    stringBuffer.append(",");
                }
                stringBuffer.deleteCharAt(stringBuffer.length() - 1);
                return stringBuffer.toString();
            } else {
                return "";
            }
        } else {
            return "";
        }
    }

    /**
     * 拆分字符串
     *
     * @param key 数据
     */
    private List<String> splitString(String key) {
        return new ArrayList<>(Arrays.asList(key.split(",")));
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        assert rootView != null;
        unbinder = ButterKnife.bind(this, rootView);
        return rootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}
